package cc.wanforme.chipmunity.test.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cc.wanforme.chipmunity.test.po.User;
import cc.wanforme.chipmunity.test.service.UserService;

/**
 * @author wanne
 * 2019年7月16日
 * 
 */
@Controller
@RequestMapping("/cm/user")
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@PostMapping("/add")
//	@ResponseBody
	public String insertUser(@RequestBody User user) {
		System.out.println("---------------User: "+user);
		try {
			userService.insert(user);
			return "success";
		} catch (Exception e) {
			e.printStackTrace();
			return "fail";
		}
	}
	
	@RequestMapping("/list")
	@ResponseBody
	public List<User> list() {
		List<User> list = userService.list();
		for (User user : list) {
			System.out.println(user);
		}
		return list;
	}
	
}
